//% color="#ff9f06"
namespace BMXBMP {
    //% block="10DOF传感器初始化" blockType="command"
    export function BMXBMP_init(parameter: any, block: any) {
        Generator.addInclude('DFRobot_BMXBMP', '#include <DFRobot_BMX160.h>');
        Generator.addInclude('DFRobot_BMXBMP1', '#include <DFRobot_BMP388_I2C_1.h>');
        // Generator.addInclude('DFRobot_BMXBMP2', '#include <bmp3_defs.h>');
        // Generator.addInclude('DFRobot_BMXBMP3', '#include <DFRobot_BMP388.h>');
        Generator.addObject(`DFRobot_BMXBMP1`, `DFRobot_BMP388_I2C `, `bmp_388;`);
        Generator.addObject(`DFRobot_BMXBMP2`, `DFRobot_BMX160  `, `bmx160;`);
        Generator.addSetup("bmp_388.begin", `
  while(bmp_388.begin()){
    Serial.println("Initialize error!");
    delay(1000);
  }
  if(bmx160.begin() != true){
    Serial.println("init false");
    while(1);
  }   `);
    }
    //% block="BMX160" blockType="tag"
    export function tagtest() {}
    //% block="BMX160读取一次数据存入并结果" blockType="command"
    export function BMXBMP_read(parameter: any, block: any) {

        Generator.addCode('sBmx160SensorData_t Omagn, Ogyro, Oaccel;\n  bmx160.getAllData(&Omagn, &Ogyro, &Oaccel);\n')
    }

    //% block="获取磁力计[XYZ]的磁场值(uT)" blockType="reporter"
    //% XYZ.shadow="dropdown" XYZ.options="XYZ"
    export function BMXBMP_Omagn(parameter: any, block: any) {

        let XYZ = parameter.XYZ.code;
        Generator.addCode(`Omagn.${XYZ}`)
    }
    //% block="获取[XYZ]的加速度值(g)" blockType="reporter"
    //% XYZ.shadow="dropdown" XYZ.options="XYZ"
    export function BMXBMP_Oaccel(parameter: any, block: any) {

        let XYZ = parameter.XYZ.code;
        Generator.addCode(`Oaccel.${XYZ}`)
    }
    //% block="获取[XYZ]的陀螺仪值(m/s^2)" blockType="reporter"
    //% XYZ.shadow="dropdown" XYZ.options="XYZ"
    export function BMXBMP_Ogyro(parameter: any, block: any) {

        let XYZ = parameter.XYZ.code;
        Generator.addCode(`Ogyro.${XYZ}`)
    }

    //% block="BMP388" blockType="tag"
    export function tagtes1t() {}
    
    //% block="获取海报高度(m)" blockType="reporter"
    export function BMXBMP_readAltitude(parameter: any, block: any) {

        Generator.addCode(`bmp_388.readAltitude()`)
    }
    //% block="获取大气压强(Pa)" blockType="reporter"
    export function BMXBMP_readPressPa(parameter: any, block: any) {
        Generator.addCode(`bmp_388.readPressure()`)
    }
    //% block="获取温度(℃)" blockType="reporter"
    export function BMXBMP_readTempC(parameter: any, block: any) {
        Generator.addCode(`bmp_388.readTemperature()`)
    }
}